package com.empire.module.sporttery.convert.footballmatch;


import com.empire.framework.common.util.collection.CollectionUtils;
import com.empire.framework.common.util.date.LocalDateTimeUtils;
import com.empire.module.spider.api.dto.FootballMatchSportteryDTO;
import com.empire.module.sporttery.controller.app.football.vo.AppFootballMatchSportteryItemRespVO;
import com.empire.module.sporttery.controller.app.football.vo.AppFootballMatchSportteryRespVO;
import com.empire.module.sporttery.controller.app.football.vo.CalculateBonusMatchReqVO;
import com.empire.module.sporttery.vo.*;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Mapper
public interface FootballMatchConvert {

    FootballMatchConvert INSTANCE = Mappers.getMapper(FootballMatchConvert.class);
    /**
     * 胜平负赔率字符串 转换 胜平负
     * @param spfBonus
     * @param single
     * @return
     */
    default List<BonusVO> convert2spfBonus(String spfBonus,String single) {
        if (spfBonus==null||spfBonus.isBlank()) {
            return null;
        }
        //胜，平，负
        String[]ss = spfBonus.split(",");

        BonusVO s=new BonusVO("胜",Double.valueOf(ss[0]),false,1,"s","spf");
        BonusVO p=new BonusVO("平",Double.valueOf(ss[1]),false,1,"p","spf");
        BonusVO f=new BonusVO("负",Double.valueOf(ss[2]),false,1,"f","spf");

        //是否单关
        Boolean danguan = Objects.equals(single, "1");
        s.setS(danguan);
        p.setS(danguan);
        f.setS(danguan);


        List<BonusVO> list=new ArrayList<>();
        list.add(s);
        list.add(p);
        list.add(f);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        return list;
    }
    /**
     * 让球胜平负赔率字符串 转换 让球胜平负
     * @param rspfBonus
     * @param single
     * @return
     */
    default List<BonusVO> convert2rspfBonus(String rspfBonus, String goalline, String single) {
        if (rspfBonus==null||rspfBonus.isBlank()) {
            return null;
        }
        //胜，平，负
        String[]ss = rspfBonus.split(",");

        BonusVO s=new BonusVO(goalline+" 胜",Double.valueOf(ss[0]),false,1,"rs","rspf");
        BonusVO p=new BonusVO(goalline+" 平",Double.valueOf(ss[1]),false,1,"rp","rspf");
        BonusVO f=new BonusVO(goalline+" 负",Double.valueOf(ss[2]),false,1,"rf","rspf");

        //是否单关
        Boolean danguan = Objects.equals(single, "1");
        s.setS(danguan);
        p.setS(danguan);
        f.setS(danguan);

        List<BonusVO> list=new ArrayList<>();
        list.add(s);
        list.add(p);
        list.add(f);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        return list;
    }

    /**
     * 半全场赔率字符串 转换 半全场
     * @param bqcBonus
     * @return
     */
    default List<BonusVO> convert2bqcBonus(String bqcBonus) {
        if (bqcBonus==null||bqcBonus.isBlank()) {
            return null;
        }
        String[] bonus = bqcBonus.split(",");
        BonusVO ss=new BonusVO("胜胜",Double.valueOf(bonus[0]),false,1,"ss","bqc");
        BonusVO sp=new BonusVO("胜平",Double.valueOf(bonus[1]),false,1,"sp","bqc");
        BonusVO sf=new BonusVO("胜负",Double.valueOf(bonus[2]),false,1,"sf","bqc");
        BonusVO ps=new BonusVO("平胜",Double.valueOf(bonus[3]),false,1,"ps","bqc");
        BonusVO pp=new BonusVO("平平",Double.valueOf(bonus[4]),false,1,"pp","bqc");
        BonusVO pf=new BonusVO("平负",Double.valueOf(bonus[5]),false,1,"pf","bqc");
        BonusVO fs=new BonusVO("负胜",Double.valueOf(bonus[6]),false,1,"fs","bqc");
        BonusVO fp=new BonusVO("负平",Double.valueOf(bonus[7]),false,1,"fp","bqc");
        BonusVO ff=new BonusVO("负负",Double.valueOf(bonus[8]),false,1,"ff","bqc");

        List<BonusVO> list=new ArrayList<>();
        list.add(ss);
        list.add(sp);
        list.add(sf);
        list.add(ps);
        list.add(pp);
        list.add(pf);
        list.add(fs);
        list.add(fp);
        list.add(ff);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }

        return list;
    }
    /**
     * 总进球赔率字符串 转换 总进球
     * @param ttgBonus
     * @return
     */
    default List<BonusVO> convert2ttgBonus(String ttgBonus) {
        if (ttgBonus==null||ttgBonus.isBlank()) {
            return null;
        }
        String[] bonus = ttgBonus.split(",");
        BonusVO q0=new BonusVO("0球",Double.valueOf(bonus[0]),false,1,"s0","ttg");
        BonusVO q1=new BonusVO("1球",Double.valueOf(bonus[1]),false,1,"s1","ttg");
        BonusVO q2=new BonusVO("2球",Double.valueOf(bonus[2]),false,1,"s2","ttg");
        BonusVO q3=new BonusVO("3球",Double.valueOf(bonus[3]),false,1,"s3","ttg");
        BonusVO q4=new BonusVO("4球",Double.valueOf(bonus[4]),false,1,"s4","ttg");
        BonusVO q5=new BonusVO("5球",Double.valueOf(bonus[5]),false,1,"s5","ttg");
        BonusVO q6=new BonusVO("6球",Double.valueOf(bonus[6]),false,1,"s6","ttg");
        BonusVO q7=new BonusVO("7+球",Double.valueOf(bonus[7]),false,1,"s7","ttg");

        List<BonusVO> list=new ArrayList<>();
        list.add(q0);
        list.add(q1);
        list.add(q2);
        list.add(q3);
        list.add(q4);
        list.add(q5);
        list.add(q6);
        list.add(q7);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        return list;
    }

    /**
     * 总进球赔率字符串 转换 总进球
     * @param crsBonus
     * @return
     */
    default List<BonusVO> convert2crsBonus(String crsBonus) {
        if (crsBonus==null||crsBonus.isBlank()) {
            return null;
        }
        String[] bonus = crsBonus.split(",");
        BonusVO s10=new BonusVO("1:0",Double.valueOf(bonus[0]),false,1,"q10","crs");
        BonusVO s20=new BonusVO("2:0",Double.valueOf(bonus[1]),false,1,"q20","crs");
        BonusVO s21=new BonusVO("2:1",Double.valueOf(bonus[2]),false,1,"q21","crs");
        BonusVO s30=new BonusVO("3:0",Double.valueOf(bonus[3]),false,1,"q30","crs");
        BonusVO s31=new BonusVO("3:1",Double.valueOf(bonus[4]),false,1,"q31","crs");
        BonusVO s32=new BonusVO("3:2",Double.valueOf(bonus[5]),false,1,"q32","crs");
        BonusVO s40=new BonusVO("4:0",Double.valueOf(bonus[6]),false,1,"q40","crs");
        BonusVO s41=new BonusVO("4:1",Double.valueOf(bonus[7]),false,1,"q41","crs");
        BonusVO s42=new BonusVO("4:2",Double.valueOf(bonus[8]),false,1,"q42","crs");
        BonusVO s50=new BonusVO("5:0",Double.valueOf(bonus[9]),false,1,"q50","crs");
        BonusVO s51=new BonusVO("5:1",Double.valueOf(bonus[10]),false,1,"q51","crs");
        BonusVO s52=new BonusVO("5:2",Double.valueOf(bonus[11]),false,1,"q52","crs");
        BonusVO s53=new BonusVO("胜其他",Double.valueOf(bonus[12]),false,1,"q53","crs");

        BonusVO s00=new BonusVO("0:0",Double.valueOf(bonus[13]),false,1,"q00","crs");
        BonusVO s11=new BonusVO("1:1",Double.valueOf(bonus[14]),false,1,"q11","crs");
        BonusVO s22=new BonusVO("2:2",Double.valueOf(bonus[15]),false,1,"q22","crs");
        BonusVO s33=new BonusVO("3:3",Double.valueOf(bonus[16]),false,1,"q33","crs");
        BonusVO s44=new BonusVO("平其他",Double.valueOf(bonus[17]),false,1,"q44","crs");

        BonusVO s01=new BonusVO("0:1",Double.valueOf(bonus[18]),false,1,"q01","crs");
        BonusVO s02=new BonusVO("0:2",Double.valueOf(bonus[19]),false,1,"q02","crs");
        BonusVO s12=new BonusVO("1:2",Double.valueOf(bonus[20]),false,1,"q12","crs");
        BonusVO s03=new BonusVO("0:3",Double.valueOf(bonus[21]),false,1,"q03","crs");
        BonusVO s13=new BonusVO("1:3",Double.valueOf(bonus[22]),false,1,"q13","crs");
        BonusVO s23=new BonusVO("2:3",Double.valueOf(bonus[23]),false,1,"q23","crs");
        BonusVO s04=new BonusVO("0:4",Double.valueOf(bonus[24]),false,1,"q04","crs");
        BonusVO s14=new BonusVO("1:4",Double.valueOf(bonus[25]),false,1,"q14","crs");
        BonusVO s24=new BonusVO("2:4",Double.valueOf(bonus[26]),false,1,"q24","crs");
        BonusVO s05=new BonusVO("0:5",Double.valueOf(bonus[27]),false,1,"q05","crs");
        BonusVO s15=new BonusVO("1:5",Double.valueOf(bonus[28]),false,1,"q15","crs");
        BonusVO s25=new BonusVO("2:5",Double.valueOf(bonus[29]),false,1,"q25","crs");
        BonusVO s35=new BonusVO("负其他",Double.valueOf(bonus[30]),false,1,"q35","crs");

        List<BonusVO> list=new ArrayList<>();
        list.add(s10);
        list.add(s20);
        list.add(s21);
        list.add(s30);
        list.add(s31);
        list.add(s32);
        list.add(s40);
        list.add(s41);
        list.add(s42);
        list.add(s50);
        list.add(s51);
        list.add(s52);
        list.add(s53);
        list.add(s00);
        list.add(s11);
        list.add(s22);
        list.add(s33);
        list.add(s44);
        list.add(s01);
        list.add(s02);
        list.add(s12);
        list.add(s03);
        list.add(s13);
        list.add(s23);
        list.add(s04);
        list.add(s14);
        list.add(s24);
        list.add(s05);
        list.add(s15);
        list.add(s25);
        list.add(s35);

        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        return list;
    }
    /**
     * 胜平负赔率字符串 转换 胜平负
     * @param spfBonus
     * @param single
     * @return
     */
    default SpfItemVO convert2spfItem(String spfBonus,String single) {
        if (spfBonus==null||spfBonus.isBlank()) {
            return null;
        }
        //胜，平，负
        String[]ss = spfBonus.split(",");

        BonusVO s=new BonusVO("胜",Double.valueOf(ss[0]),false,1,"s","spf");
        BonusVO p=new BonusVO("平",Double.valueOf(ss[1]),false,1,"p","spf");
        BonusVO f=new BonusVO("负",Double.valueOf(ss[2]),false,1,"f","spf");

        List<BonusVO> list=new ArrayList<>();
        list.add(s);
        list.add(p);
        list.add(f);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }

        //是否单关
        Boolean danguan = Objects.equals(single, "1");

        return new SpfItemVO(s,p,f,danguan,"spf");
    }
    /**
     * 让球胜平负赔率字符串 转换 让球胜平负
     * @param rspfBonus
     * @param single
     * @return
     */
    default RspfItemVO convert2rspfItem(String rspfBonus, String goalline, String single) {
        if (rspfBonus==null||rspfBonus.isBlank()) {
            return null;
        }
        //胜，平，负
        String[]ss = rspfBonus.split(",");

        BonusVO s=new BonusVO("胜",Double.valueOf(ss[0]),false,1,"rs","rspf");
        BonusVO p=new BonusVO("平",Double.valueOf(ss[1]),false,1,"rp","rspf");
        BonusVO f=new BonusVO("负",Double.valueOf(ss[2]),false,1,"rf","rspf");

        List<BonusVO> list=new ArrayList<>();
        list.add(s);
        list.add(p);
        list.add(f);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }

        //是否单关
        Boolean danguan = Objects.equals(single, "1");

        return new RspfItemVO(s,p,f,goalline,danguan,"rspf");
    }
    /**
     * 半全场赔率字符串 转换 半全场
     * @param bqcBonus
     * @return
     */
    default BqcItemVO convert2bqcItem(String bqcBonus) {
        if (bqcBonus==null||bqcBonus.isBlank()) {
            return null;
        }
        String[] bonus = bqcBonus.split(",");
        BonusVO ss=new BonusVO("胜胜",Double.valueOf(bonus[0]),false,1,"ss","bqc");
        BonusVO sp=new BonusVO("胜平",Double.valueOf(bonus[1]),false,1,"sp","bqc");
        BonusVO sf=new BonusVO("胜负",Double.valueOf(bonus[2]),false,1,"sf","bqc");
        BonusVO ps=new BonusVO("平胜",Double.valueOf(bonus[3]),false,1,"ps","bqc");
        BonusVO pp=new BonusVO("平平",Double.valueOf(bonus[4]),false,1,"pp","bqc");
        BonusVO pf=new BonusVO("平负",Double.valueOf(bonus[5]),false,1,"pf","bqc");
        BonusVO fs=new BonusVO("负胜",Double.valueOf(bonus[6]),false,1,"fs","bqc");
        BonusVO fp=new BonusVO("负平",Double.valueOf(bonus[7]),false,1,"fp","bqc");
        BonusVO ff=new BonusVO("负负",Double.valueOf(bonus[8]),false,1,"ff","bqc");

        List<BonusVO> list=new ArrayList<>();
        list.add(ss);
        list.add(sp);
        list.add(sf);
        list.add(ps);
        list.add(pp);
        list.add(pf);
        list.add(fs);
        list.add(fp);
        list.add(ff);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }

        return new BqcItemVO(ss,sp,sf,ps,pp,pf,fs,fp,ff,"bqc");
    }
    /**
     * 总进球赔率字符串 转换 总进球
     * @param ttgBonus
     * @return
     */
    default TtgItemVO convert2ttgItem(String ttgBonus) {
        if (ttgBonus==null||ttgBonus.isBlank()) {
            return null;
        }
        String[] bonus = ttgBonus.split(",");
        BonusVO q0=new BonusVO("0球",Double.valueOf(bonus[0]),false,1,"s0","ttg");
        BonusVO q1=new BonusVO("1球",Double.valueOf(bonus[1]),false,1,"s1","ttg");
        BonusVO q2=new BonusVO("2球",Double.valueOf(bonus[2]),false,1,"s2","ttg");
        BonusVO q3=new BonusVO("3球",Double.valueOf(bonus[3]),false,1,"s3","ttg");
        BonusVO q4=new BonusVO("4球",Double.valueOf(bonus[4]),false,1,"s4","ttg");
        BonusVO q5=new BonusVO("5球",Double.valueOf(bonus[5]),false,1,"s5","ttg");
        BonusVO q6=new BonusVO("6球",Double.valueOf(bonus[6]),false,1,"s6","ttg");
        BonusVO q7=new BonusVO("7+球",Double.valueOf(bonus[7]),false,1,"s7","ttg");

        List<BonusVO> list=new ArrayList<>();
        list.add(q0);
        list.add(q1);
        list.add(q2);
        list.add(q3);
        list.add(q4);
        list.add(q5);
        list.add(q6);
        list.add(q7);
        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        return new TtgItemVO(q0,q1,q2,q3,q4,q5,q6,q7,"ttg");
    }

    /**
     * 总进球赔率字符串 转换 总进球
     * @param crsBonus
     * @return
     */
    default CrsItemVO convert2crsItem(String crsBonus) {
        if (crsBonus==null||crsBonus.isBlank()) {
            return null;
        }
        String[] bonus = crsBonus.split(",");
        BonusVO s10=new BonusVO("1:0",Double.valueOf(bonus[0]),false,1,"q10","crs");
        BonusVO s20=new BonusVO("2:0",Double.valueOf(bonus[1]),false,1,"q20","crs");
        BonusVO s21=new BonusVO("2:1",Double.valueOf(bonus[2]),false,1,"q21","crs");
        BonusVO s30=new BonusVO("3:0",Double.valueOf(bonus[3]),false,1,"q30","crs");
        BonusVO s31=new BonusVO("3:1",Double.valueOf(bonus[4]),false,1,"q31","crs");
        BonusVO s32=new BonusVO("3:2",Double.valueOf(bonus[5]),false,1,"q32","crs");
        BonusVO s40=new BonusVO("4:0",Double.valueOf(bonus[6]),false,1,"q40","crs");
        BonusVO s41=new BonusVO("4:1",Double.valueOf(bonus[7]),false,1,"q41","crs");
        BonusVO s42=new BonusVO("4:2",Double.valueOf(bonus[8]),false,1,"q42","crs");
        BonusVO s50=new BonusVO("5:0",Double.valueOf(bonus[9]),false,1,"q50","crs");
        BonusVO s51=new BonusVO("5:1",Double.valueOf(bonus[10]),false,1,"q51","crs");
        BonusVO s52=new BonusVO("5:2",Double.valueOf(bonus[11]),false,1,"q52","crs");
        BonusVO s53=new BonusVO("胜其他",Double.valueOf(bonus[12]),false,1,"q53","crs");

        BonusVO s00=new BonusVO("0:0",Double.valueOf(bonus[13]),false,1,"q00","crs");
        BonusVO s11=new BonusVO("1:1",Double.valueOf(bonus[14]),false,1,"q11","crs");
        BonusVO s22=new BonusVO("2:2",Double.valueOf(bonus[15]),false,1,"q22","crs");
        BonusVO s33=new BonusVO("3:3",Double.valueOf(bonus[16]),false,1,"q33","crs");
        BonusVO s44=new BonusVO("平其他",Double.valueOf(bonus[17]),false,1,"q44","crs");

        BonusVO s01=new BonusVO("0:1",Double.valueOf(bonus[18]),false,1,"q01","crs");
        BonusVO s02=new BonusVO("0:2",Double.valueOf(bonus[19]),false,1,"q02","crs");
        BonusVO s12=new BonusVO("1:2",Double.valueOf(bonus[20]),false,1,"q12","crs");
        BonusVO s03=new BonusVO("0:3",Double.valueOf(bonus[21]),false,1,"q03","crs");
        BonusVO s13=new BonusVO("1:3",Double.valueOf(bonus[22]),false,1,"q13","crs");
        BonusVO s23=new BonusVO("2:3",Double.valueOf(bonus[23]),false,1,"q23","crs");
        BonusVO s04=new BonusVO("0:4",Double.valueOf(bonus[24]),false,1,"q04","crs");
        BonusVO s14=new BonusVO("1:4",Double.valueOf(bonus[25]),false,1,"q14","crs");
        BonusVO s24=new BonusVO("2:4",Double.valueOf(bonus[26]),false,1,"q24","crs");
        BonusVO s05=new BonusVO("0:5",Double.valueOf(bonus[27]),false,1,"q05","crs");
        BonusVO s15=new BonusVO("1:5",Double.valueOf(bonus[28]),false,1,"q15","crs");
        BonusVO s25=new BonusVO("2:5",Double.valueOf(bonus[29]),false,1,"q25","crs");
        BonusVO s35=new BonusVO("负其他",Double.valueOf(bonus[30]),false,1,"q35","crs");

        List<BonusVO> list=new ArrayList<>();
        list.add(s10);
        list.add(s20);
        list.add(s21);
        list.add(s30);
        list.add(s31);
        list.add(s32);
        list.add(s40);
        list.add(s41);
        list.add(s42);
        list.add(s50);
        list.add(s51);
        list.add(s52);
        list.add(s53);
        list.add(s00);
        list.add(s11);
        list.add(s22);
        list.add(s33);
        list.add(s44);
        list.add(s01);
        list.add(s02);
        list.add(s12);
        list.add(s03);
        list.add(s13);
        list.add(s23);
        list.add(s04);
        list.add(s14);
        list.add(s24);
        list.add(s05);
        list.add(s15);
        list.add(s25);
        list.add(s35);

        //转换赔数，一二三陪，赔率小到大
        list.sort((a,b)->Double.compare(a.getV(),b.getV()));
        for(int i=0;i<list.size();i++){
            list.get(i).setPei(i+1);
        }
        CrsItemVO crs = new CrsItemVO();
        crs.setGameCode("crs");
        crs.setS10(s10);
        crs.setS20(s20);
        crs.setS21(s21);
        crs.setS30(s30);
        crs.setS31(s31);
        crs.setS32(s32);
        crs.setS40(s40);
        crs.setS41(s41);
        crs.setS42(s42);
        crs.setS50(s50);
        crs.setS51(s51);
        crs.setS52(s52);
        crs.setS53(s53);

        crs.setS00(s00);
        crs.setS11(s11);
        crs.setS22(s22);
        crs.setS33(s33);
        crs.setS44(s44);

        crs.setS01(s01);
        crs.setS02(s02);
        crs.setS12(s12);
        crs.setS03(s03);
        crs.setS13(s13);
        crs.setS23(s23);
        crs.setS04(s04);
        crs.setS14(s14);
        crs.setS24(s24);
        crs.setS05(s05);
        crs.setS15(s15);
        crs.setS25(s25);
        crs.setS35(s35);

        return crs;
    }

    default AppFootballMatchSportteryItemRespVO convert(FootballMatchSportteryDTO footballMatchDTO) {
        if ( footballMatchDTO == null ) {
            return null;
        }
        AppFootballMatchSportteryItemRespVO m = new AppFootballMatchSportteryItemRespVO();

        m.setMatchId( footballMatchDTO.getMatchId() );
        m.setBusinessDate( footballMatchDTO.getBusinessDate() );
        m.setHomeTeamAbbName( footballMatchDTO.getHomeTeamAbbName() );
        m.setHomeTeamId( footballMatchDTO.getHomeTeamId() );
        m.setAwayTeamAbbName( footballMatchDTO.getAwayTeamAbbName() );
        m.setAwayTeamId( footballMatchDTO.getAwayTeamId() );
        m.setLeagueAbbName( footballMatchDTO.getLeagueAbbName() );
        m.setMatchDate( footballMatchDTO.getMatchDate() );
        m.setMatchNum( footballMatchDTO.getMatchNum() );
        m.setMatchNumStr( footballMatchDTO.getMatchNumStr() );
        m.setMatchStatus( footballMatchDTO.getMatchStatus() );
        m.setMatchTime( footballMatchDTO.getMatchTime() );
        m.setSellStatus( footballMatchDTO.getSellStatus() );

        m.setMatchDateStr( footballMatchDTO.getMatchDate().substring(5) );

        m.setSpfBonus(convert2spfItem(footballMatchDTO.getSpfBonus(),footballMatchDTO.getSpfSingle()));
        m.setRspfBonus(convert2rspfItem(footballMatchDTO.getRspfBonus(),footballMatchDTO.getGoalLine(),footballMatchDTO.getRspfSingle()));
        m.setBqcBonus(convert2bqcItem(footballMatchDTO.getBqcBonus()));
        m.setTtgBonus(convert2ttgItem(footballMatchDTO.getTtgBonus()));
        m.setCrsBonus(convert2crsItem(footballMatchDTO.getCrsBonus()));
        return m;
    }

    default MatchBonusItemVO convert3(FootballMatchSportteryDTO footballMatchDTO) {
        if ( footballMatchDTO == null ) {
            return null;
        }
        MatchBonusItemVO m = new MatchBonusItemVO();

        m.setMatchId( footballMatchDTO.getMatchId() );
        m.setBusinessDate( footballMatchDTO.getBusinessDate() );
        m.setHomeTeamAbbName( footballMatchDTO.getHomeTeamAbbName() );
        m.setHomeTeamId( footballMatchDTO.getHomeTeamId() );
        m.setAwayTeamAbbName( footballMatchDTO.getAwayTeamAbbName() );
        m.setAwayTeamId( footballMatchDTO.getAwayTeamId() );
        m.setLeagueAbbName( footballMatchDTO.getLeagueAbbName() );
        m.setMatchDate( footballMatchDTO.getMatchDate() );
        m.setMatchNum( footballMatchDTO.getMatchNum() );
        m.setMatchNumStr( footballMatchDTO.getMatchNumStr() );
        m.setMatchStatus( footballMatchDTO.getMatchStatus() );
        m.setMatchTime( footballMatchDTO.getMatchTime() );
        m.setSellStatus( footballMatchDTO.getSellStatus() );
        m.setMatchDateStr( footballMatchDTO.getMatchDate().substring(5) );

        List<BonusVO> list1 = convert2spfBonus(footballMatchDTO.getSpfBonus(),footballMatchDTO.getSpfSingle());
        List<BonusVO> list2 = convert2rspfBonus(footballMatchDTO.getRspfBonus(),footballMatchDTO.getGoalLine(),footballMatchDTO.getRspfSingle());
        List<BonusVO> list3 = convert2bqcBonus(footballMatchDTO.getBqcBonus());
        List<BonusVO> list4 = convert2ttgBonus(footballMatchDTO.getTtgBonus());
        List<BonusVO> list5 = convert2crsBonus(footballMatchDTO.getCrsBonus());
        list1.addAll(list2);
        list1.addAll(list3);
        list1.addAll(list4);
        list1.addAll(list5);
        m.setBonusList(list1);

        return m;
    }

    default AppMatchBonusVO convert4(MatchBonusVO vo) {
        if ( vo == null ) {
            return null;
        }
        AppMatchBonusVO m = new AppMatchBonusVO();
        m.setBonus(vo.getBonus());
        m.setGameCode(vo.getGameCode());
        m.setMatchId(vo.getMatchId());
        return m;
    }


    default List<AppFootballMatchSportteryRespVO> convertList(List<FootballMatchSportteryDTO> list,Integer type) {
        Map<String, List<AppFootballMatchSportteryItemRespVO>> groupedByBusinessDate =CollectionUtils.convertList(list, this::convert).stream()
                .collect(Collectors.groupingBy(AppFootballMatchSportteryItemRespVO::getBusinessDate));
        // 使用Stream API和LinkedHashMap来保持插入顺序
        Map<String, List<AppFootballMatchSportteryItemRespVO>> sortedMap = groupedByBusinessDate.entrySet().stream()
                .sorted(Map.Entry.comparingByKey()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));;

        List<AppFootballMatchSportteryRespVO> rlist = new ArrayList<>();
        for (String key : sortedMap.keySet()) {
            AppFootballMatchSportteryRespVO m = new AppFootballMatchSportteryRespVO();
            List<AppFootballMatchSportteryItemRespVO> orlist = groupedByBusinessDate.get(key);
            List<AppFootballMatchSportteryItemRespVO> itemlist=new ArrayList<>();

            for(AppFootballMatchSportteryItemRespVO v:orlist){
                //根据前端页面的数据需要，进行筛选
                if(type == 1){//单关
                    if(v.getSpfBonus().getSingle()!=null&&v.getSpfBonus().getSingle()){
                        itemlist.add(v);
                    }
                }else if(type == 2){
                    //2选1
                    if(v.getSpfBonus().getSingle()!=null){
                        itemlist.add(v);
                    }
                }else{
                    itemlist.add(v);
                }
            }


            //对每天的场次排序，保证场次的升序
            itemlist.sort((a,b)->Integer.compare(a.getMatchNum(),b.getMatchNum()));
            m.setBusinessDate(key);
            m.setMatchList(itemlist);
            m.setNum(itemlist.size());

            LocalDateTime businessDate = LocalDateTimeUtils.parse(key);
            //判断是否周末，周末23:00停手，其他22:00停手
            String stopTime="22:00";
            if(businessDate.getDayOfWeek()== DayOfWeek.SUNDAY||businessDate.getDayOfWeek()== DayOfWeek.SATURDAY){
                stopTime = "23:00";
            }
            m.setOverTime(stopTime);//暂时先默认，后期再升级
            if (!itemlist.isEmpty()){
                String w = itemlist.get(0).getMatchNumStr();//周四004
                if(!w.isEmpty()){
                    m.setWeek(w.substring(0,2));
                }
            }
            rlist.add(m);
        }
        return rlist;
    }

    default List<AppFootballMatchSportteryItemRespVO> convertList2(List<FootballMatchSportteryDTO> list) {
        return CollectionUtils.convertList(list, this::convert);
    }

    default List<MatchBonusItemVO> convertList3(List<FootballMatchSportteryDTO> list) {
        return CollectionUtils.convertList(list, this::convert3);
    }
    default List<AppMatchBonusVO> convertList4(List<MatchBonusVO> list) {
        return CollectionUtils.convertList(list, this::convert4);
    }
}
